﻿Imports System.Data
Imports System.Data.OleDb
Imports geraLaudosAutomatico.conexao
Imports System.Text

Public Class armaRelatorioDao

    Private sql As New StringBuilder
    Private i As Integer

    Public Function insereArmaRelatorio(ByVal armaRelatorio As armaRelatorioVO) As Integer



        'Dim numReg As Integer = 0
        'Dim objConn As New conexao
        'Dim myConnection As OleDbConnection = objConn.abreConexao
        'Dim myCommand As OleDbCommand = myConnection.CreateCommand()
        'Dim myTrans As OleDbTransaction
        '' Start a local transaction
        'myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted)
        '' Assign transaction object for a pending local transaction
        'myCommand.Connection = myConnection
        'myCommand.Transaction = myTrans
        'sql.Clear()

        'Try
        '    myCommand.CommandText = sql.ToString
        '    sql.Clear()
        '    sql.Append("INSERT INTO ARMA_RELATORIO (ID_REGISTRO,DATA_REGISTRO,ID_ARMA,ID_CALIBRE,EFICIENTE)")
        '    sql.Append(" VALUES ")
        '    sql.Append("(@ID_REGISTRO,@DATA_REGISTRO,@ID_ARMA,@ID_CALIBRE,@EFICIENTE)")
        '    myCommand.CommandText = sql.ToString
        '    myCommand.Parameters.AddWithValue("@ID_REGISTRO", armaRelatorio.ID_REGISTRO)
        '    myCommand.Parameters.AddWithValue("@DATA_REGISTRO", DateTime.Parse(Now()))
        '    myCommand.Parameters.AddWithValue("@ID_ARMA", armaRelatorio.ID_ARMA)
        '    myCommand.Parameters.AddWithValue("@ID_CALIBRE", armaRelatorio.ID_CALIBRE)
        '    myCommand.Parameters.AddWithValue("@EFICIENTE", armaRelatorio.EFICIENTE)
        '    i = myCommand.ExecuteNonQuery()
        '    myCommand.Parameters.Clear()
        '    myTrans.Commit()

        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    objConn.fechaConexao()
        'End Try
        'End
        'Return i


        Dim numReg As Integer = 0
        sql.Clear()
        sql.Append("INSERT INTO ARMA_RELATORIO (ID_REGISTRO,DATA_REGISTRO,ID_ARMA,ID_CALIBRE,EFICIENTE)")
        sql.Append(" VALUES ")
        sql.Append("(@ID_REGISTRO,@DATA_REGISTRO,@ID_ARMA,@ID_CALIBRE,@EFICIENTE)")
        Try
            Dim objConn As New conexao
            Dim oComando As New OleDbCommand(sql.ToString, objConn.abreConexao)

                  oComando.Parameters.AddWithValue("@ID_REGISTRO", armaRelatorio.ID_REGISTRO)
            oComando.Parameters.AddWithValue("@DATA_REGISTRO", DateTime.Parse(Now()))
            oComando.Parameters.AddWithValue("@ID_ARMA", armaRelatorio.ID_ARMA)
            oComando.Parameters.AddWithValue("@ID_CALIBRE", armaRelatorio.ID_CALIBRE)
            oComando.Parameters.AddWithValue("@EFICIENTE", armaRelatorio.EFICIENTE)
            i = oComando.ExecuteNonQuery

        Catch ex As Exception
            Throw ex
        End Try

        Return i

    End Function
End Class